3 Reports with R Markdown

Author

Matt Crump

Published

February 1, 2023

Read

https://psyteachr.github.io/ads-v2/02-reports.html

Overview

The textbook chapter covers writing R markdown documents (.Rmd extension). R Markdown is a notebook style coding document that can contain plain text (markdown), and executable R code chunks along with outputs, and compile everything into one output document. This system uses a package called knitr to “knit” together the plain text and code into a final output.

Our class is using a newer notebook system called quarto (.qmd extension). Most of the same concepts and syntax used in .Rmd work in .qmd.

We are just starting to learn bits of R coding. In class we have executed bits of R code in the console. Moving forward we will be writing whole scripts of code and saving our scripts in text files. It is possible to store R code in .R files, however, these script files do not allow for regular text. Instead, we will be using notebook style .qmd documents that contain both code and text.

MOST IMPORTANT: Reproducible document

The most important concept here is that we will be learning to code using a reproducible document creation system. This provides an integrated document format to write and execute code, and to write text for purposes of communication.

Basic Skills for this section

  1. Be able to make a new .qmd document
  2. Be able to render a .qmd document
  3. Explain the difference between the source editor view and visual editor view in Rstudio.
  4. Be able to insert simple markdown plain text (headers, lists, paragraphs), and render the document.
  5. Be aware of resources to help you learn more about markdown options.
  6. Be able to insert an R code chunk, and show the output in the rendered document.
  • macro for quick insert
  1. Running R code chunks in a qmd
  • pressing play
  • copy/paste into console
  • highlight then command-enter (mac)
  • precedence issues (first to last)
  1. Be aware of R code chunk options, and how to use eval, messages, error, warning, and echo.
  2. Be able to set code chunk options per chunk, and/or for the whole document. Understand rules for precedence (which options will apply if both are set.)
  3. Write inline r code.
  4. Explain how the rendering environment is different from the Rstudio environment.
  5. Be aware of more advanced quarto options for html documents, and try some of the options.

Additional resources

Quarto documents

The quarto website contains many helpful examples. We will cover aspects throughout the semester.

General tips for writing in quarto markdown:

https://quarto.org/docs/authoring/markdown-basics.html

Making an html document:

https://quarto.org/docs/output-formats/html-basics.html

Making a pdf document:

https://quarto.org/docs/output-formats/pdf-basics.html

R code chunk options:

https://quarto.org/docs/computations/execution-options.html

Week 3 assignment

  1. Write your blog post, and submit the link to this assignment on blackboard. The video tutorial gives an extended walkthrough.

At this point we are just beginning to start coding, and at the end of this session we will have learned more about using .qmd documents. We have already been using .qmd documents for our blog posts. And, we will be using throughout the semester for almost everything we do, including coding.

The blog post for this week is to write a post where you check off as many basic skills as you can for this section. The basic skills are the same as above, I put them in a code chunk to make them easier to copy.

“Checking off” the skills means making notes, or making additions/changes to your .qmd document to show yourself you can accomplish these tasks and/or understand the concepts.

1.  Be able to make a new .qmd document

2.  Be able to render a .qmd document

3.  Explain the difference between the source editor view and visual editor view in Rstudio.

4.  Be able to insert simple markdown plain text (headers, lists, paragraphs), and render the document.

5.  Be aware of resources to help you learn more about markdown options.

6.  Be able to insert an R code chunk, and show the output in the rendered document.
  -   macro for quick insert
  
7.  Running R code chunks in a qmd
  -   pressing play
  -   copy/paste into console
  -   highlight then command-enter (mac)
  -   precedence issues (first to last)

8.  Be aware of R code chunk options, and how to use eval, messages, error, warning, and echo.

9.  Be able to set code chunk options per chunk, and/or for the whole document. Understand rules for precedence (which options will apply if both are set.)

10. Write inline r code.

11. Explain how the rendering environment is different from the Rstudio environment.

12. Be aware of more advanced quarto options for html documents, and try some of the options.